package org.shagin.jfin.data.model.domain;

import java.util.ArrayList;
import java.util.List;

import org.shagin.jfin.core.Debug;
import org.shagin.jfin.data.model.Budget;
import org.shagin.jfin.data.model.CostCenter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The Class CostCenterDomain.
 */
public class CostCenterDomain extends BudgetDomain {

    public CostCenterDomain(Budget budget) {
        super(budget);
    }

    private static final Logger log = LoggerFactory
            .getLogger(CostCenterDomain.class);

    private List<CostCenter> all = new ArrayList<CostCenter>();

    /**
     * Gets the all.
     * 
     * @return the all
     */
    public List<CostCenter> getAll() {
        return all;
    }

    /**
     * Adds the.
     * 
     * @param costCenterId the cost center id
     * @return the cost center
     */
    public CostCenter add(String costCenterId) {
        Debug.traceEnter(log, costCenterId);
        CostCenter cc = findById(costCenterId);
        if (cc == null) {
            cc = new CostCenter(costCenterId, budget);
            all.add(cc);
        }
        return cc;
    }

    /**
     * Find by id.
     * 
     * @param costCenterId the cost center id
     * @return the cost center
     */
    public CostCenter findById(String costCenterId) {
        CostCenter cc = null;
        for (CostCenter costCenter : all) {
            if (costCenterId.equals(costCenter.getId())) {
                cc = costCenter;
                break;
            }
        }
        return cc;
    }

}
